////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file   CollabRCBot\ArithmeticMeanTreeNode.cpp
///
/// @brief  Implementation of the CollabRC::Bot::AI::ArithmeticMeanTreeNode class
////////////////////////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ArithmeticMeanTreeNode.h"
#include "ComputationalTreeNodeVisitor.h"

using CollabRC::Bot::AI::ComputationalTreeNode;
using CollabRC::Bot::AI::OperationTreeNode;
using CollabRC::Bot::AI::ArithmeticMeanTreeNode;

/**
 * @brief creates a new ArithmeticMeanTreeNode operating on the specified two branches
 * @param lhs the left hand branch of the operation
 * @param rhs the right hand branch of the operation
 */
ArithmeticMeanTreeNode::ArithmeticMeanTreeNode(const ComputationalTreeNode& lhs, const ComputationalTreeNode& rhs)
:OperationTreeNode(lhs, rhs)
{
}

/**
 * @brief Creates a duplciate ArithmeticMeanTreeNode object from the specified
 * OperationTreeNode
 * @param copy the object from which to copy the operation
 */
ArithmeticMeanTreeNode::ArithmeticMeanTreeNode(const OperationTreeNode& copy)
:OperationTreeNode(copy)
{
}

/** @brief deallocates this ArithmeticMeanTreeNode object and all associated resources */
ArithmeticMeanTreeNode::~ArithmeticMeanTreeNode(void)
{
}

/** {@inheritDoc} */
float ArithmeticMeanTreeNode::PerformOperation(float lhs, float rhs) const
{
    return (lhs + rhs) / 2.0f;  // Upcasting to double for this is 1 bit of precision. Not worth it.
}

/** {@inheritDoc} */
CollabRC::Bot::AI::ComputationalTreeNode* ArithmeticMeanTreeNode::Clone() const
{
    return new ArithmeticMeanTreeNode(*this);
}

ArithmeticMeanTreeNode::Factory ArithmeticMeanTreeNode::factory;

/** {@inheritDoc} */
ComputationalTreeNode* ArithmeticMeanTreeNode::Factory::Instantiate(const ComputationalTreeNode &lhs, const ComputationalTreeNode &rhs) const
{
    return new ArithmeticMeanTreeNode(lhs, rhs);
}

/** @brief Creates and registers this OperationalTreeNodeFactory object */
ArithmeticMeanTreeNode::Factory::Factory()
{
    OperationTreeNode::RegisterOperationTreeNodeFactory(this);
}

/** {@inheritDoc} */
void ArithmeticMeanTreeNode::Accept(CollabRC::Bot::AI::ComputationalTreeNodeVisitor &visitor)
{
    OperationTreeNode::Accept(visitor);
    visitor.Visit(*this);
}